<template>
  <div class="error">
    <div class="text">
      页面不存在，{{djs}}秒后返回
      <span @click="goBack">返回上一页</span>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      djs: 5,
      timer: null
    }
  },
  methods: {
    goBack() {
      clearInterval(this.timer)
      if (window.history.length == 1) {
        this.$router.push('/')
        return false
      }
      this.$router.go(-1)
    }
  },
  mounted() {
    this.timer = setInterval(() => {
      this.djs--
      if (this.djs === 0) {
        this.goBack()
        clearInterval(this.timer)
      }
    }, 1000)
  }
}
</script>
<style lang="scss" scoped>
  .error{
    max-width: 500px;
    width: 100%;
    height: 300px;
    margin: 0 auto;
    overflow: hidden;
    .text{
      margin-top: 50px;
      box-sizing: border-box;
      background: #eee;
      width: 100%;
      max-height: 250px;
      height: 100%;
      text-align: center;
      line-height: 250px;
      border-radius: 8px;
      border: 1px solid #dadada;
      font-size: 15px;
      span{
        margin-left: 10px;
        text-decoration: underline;
        color: #0000ff;
        cursor: pointer;
      }
    }
  }
</style>
